const { bfmetaSDK } = require('./util')

const signature = async (_message, _secretKey) => {
    // sdk返回的buffer字段为base64编码字符串
    const message = Buffer.from(_message, "base64")
    // 通过signIn接口返回的是16进制编码字符串
    const secretKey = Buffer.from(_secretKey, "hex")
    // 生成签名
    return (await bfmetaSDK.bfchainSignUtil.detachedSign(message, secretKey)).toString("hex");
}

const isAddress = (_address) => {
    // 判断地址是否合法
    return bfmetaSDK.bfchainSignUtil.isAddress(_address)
}

module.exports = {signature, isAddress}